2

How to replace an image in DIV dynamically on click of some other div image as shown in image. Requirement is like that : on click of "DIV1" root should be updated with 1.. on click of "Div2" root should be updated with 2 like that. All div having image loading from some URL and Root is a bigger div. enter image description here

please reply ...

1 Answer 1

2

You can do something like this:

<div>
   <h:graphicImage id="root" value="#{managedBean.rootImage}" alt="image"/>
</div>

<div>
   <h:commandLink>
     <h:graphicImage value="images/image1.png" alt="image1"/>
     <f:setPropertyActionListener target="#{managedBean.rootImage}" value="images/image1.png" />
     <f:ajax event="action" render="root"/>  
   </h:commandLink>
</div>

And in your ManagedBean create setter/getters like this:

public class ManagedBean{
    public String rootImage;
    public void setRootImage(String image) {
      this.rootImage= image;
    }
    public String getRootImage() {
      return rootImage;
    }
}

Reference: JSF - Two Questions about actions on UIComponent

Sign up to request clarification or add additional context in comments.

7 Comments

<f:ajax> is not a valid syntax for jsf what i am using any alternative for this ... which will solve my problem
oh if you are using JSF 1.2 then read this stackoverflow.com/questions/3545539/…
<f:ajax> is not a valid syntax for jsf ... it is giving message like this... i am using jsf 2.0
i am using <%@ taglib prefix="f" uri="java.sun.com/jsf/core"%> as tag line in my code that is the reason i guess it is giving error ..
See the documentation for syntax at this link
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.