<h:form>
<table>
<tr>
<td><label>First Name:</label></td>
<td><h:outputText value="#{profile.firstName}"
rendered="#{not profile.canEdit}" /></td>
<td><h:inputText value="#{profile.firstName}"
rendered="#{profile.canEdit}" required="true" /></td>
<td><h:commandButton value="Edit"
action="#{profile.editDetail}" /></td>
<td><h:commandButton value="Cancel" type="button"
action="#{profile.cancelBtn}" /></td>
</tr>
<tr>
<td><label>Last Name:</label></td>
<td><h:outputText value="#{profile.lastName}"
rendered="#{not profile.canEdit}" /></td>
<td><h:inputText value="#{profile.lastName}"
rendered="#{profile.canEdit}" required="true" /></td>
<td><h:commandButton value="Edit"
action="#{profile.editDetail}" /></td>
<td><h:commandButton value="Cancel" type="button"
action="#{profile.cancelBtn}" /></td>
</tr>
<tr>
<td><label>Email:</label></td>
<td><h:outputText value="#{profile.email}"
rendered="#{not profile.canEdit}" /></td>
<td><h:inputText value="#{profile.email}" id="email"
rendered="#{profile.canEdit}" required="true" /></td>
<td><h:commandButton value="Edit"
action="#{profile.editDetail}" /></td>
<td><h:commandButton value="Cancel" type="button"
action="#{profile.cancelBtn}" /></td>
<td><h:message for="email" value="#{profile.errorMessage}"
rendered="#{profile.errorMessage ne null}" /></td>
</tr>
<tr>
<td><label>Password:</label></td>
<td><h:outputText value="#{profile.password}"
rendered="#{not profile.canEdit}" /></td>
<td><h:commandButton value="Edit"
action="#{profile.editDetail}" /></td>
<td><h:commandButton value="Cancel" type="button"
action="#{profile.cancelBtn}" /></td>
</tr>
<h:panelGroup rendered="#{profile.canEdit}">
<tr>
<td><label>Old Password: </label></td>
<td><h:inputText value="#{profile.password}" required="true" /></td>
<td><h:outputText rendered="#{profile.errorMessage != null}"
value="#{profile.errorMessage}"></h:outputText></td>
</tr>
<tr>
<td><label>New Password: </label></td>
<td><h:inputSecret value="#{profile.newPassword}"
required="true" /></td>
</tr>
<tr>
<td><label>Confirm Password: </label></td>
<td><h:inputSecret value="#{profile.confirmPassword}"
required="true" /></td>
<td><h:outputText
rendered="#{profile.confirmPassword != profile.newPassword}"
value="Passwords donot match!!"></h:outputText></td>
</tr>
<tr>
<td><h:commandButton action="#{profile.savePassword}"
value="Save Password"
disabled="#{profile.confirmPassword != profile.newPassword}" /></td>
<td><h:commandButton action="#{profile.cancelBtn}" value="Cancel" type="button"/></td>
</tr>
</h:panelGroup>
<tr>
<td><label>Gender</label></td>
<td>#{profile.gender}</td>
</tr>
<tr>
<td><label>City</label></td>
<td>#{profile.city}</td>
</tr>
<tr>
<td><label>State</label></td>
<td>#{profile.state}</td>
</tr>
<tr>
<td><label>Country</label></td>
<td>#{profile.country}</td>
</tr>
<tr>
<td><label>Zip-Code</label></td>
<td>#{profile.zipCode}</td>
</tr>
<tr>
<td><label>Phone Number</label></td>
<td>#{profile.phoneNumber}</td>
</tr>
<tr>
<td><h:commandButton action="#{profile.saveDetails}"
disabled="#{profile.canEdit eq 'false'}" value="Save" /></td>
<td><h:commandButton action="#{profile.cancelBtn}" type="button"
value="Cancel" /></td>
</tr>
</table>
</h:form>
My code snippet of my backing bean
public String InitializeValues(){
customer = (CustomerVO) sessionManager.getSession("CustomerBean");
System.out.println("inside profilepagecontroller"+"\n"+ customer);
setFirstName(customer.getFirstName());
this.setLastName(customer.getLastName());
this.setEmail(customer.getEmail());
this.setPassword(customer.getPassword());
this.setCity(customer.getCity());
this.setState(customer.getState());
this.setCountry(customer.getCountry());
this.setPhoneNumber(customer.getPhoneNumber());
this.setGender(customer.getGender());
this.setZipCode(customer.getZipCode());
this.setCustomerId(customer.getCustomerId());
return "ProfilePage";
}
public String editDetail(){
setCanEdit(true);
setCanSave(true);
return null;
}
public String cancelBtn(){
setCanEdit(false);
return "ProfilePage";
}
Problems and solutions i need
when i click on cancelbutton, canEdit sets to false, but the
inputText does not get 'un'rendered on the screen. it does not render
outputText.
how do i get only a particular field in edit mode after i click edit?( creating separate boolean values for each field obv not
feasible)
setter methods set the values of fields of backing beans. after i run the code, same are not displayed on the screen. 'this' gets all
the values which i need to display, but not displayed on screen.
when i click on cancelbutton, canEdit sets to false, but the inputText
does not get 'un'rendered on the screen. it does not render outputText
Your commandButton has type="button" that shouldn't be the case.
how do i get only a particular field in edit mode after i click edit?(
creating separate boolean values for each field obv not feasible)
Huh Sure it is feasible. The only scenario I'd see you using that is if validation didn't pass for some component. Then I think you could try #{component.valid} in rendered. The problem is that all the component will be vaalid at the start then the invalid will not be rendered. To solve that check if the request is a postback:
public boolean isPostback(){
return FacesContext.getCurrentInstance().isPostback();
}
rendered="#{component.valid and not mybean.postback}"
setter methods set the values of fields of backing beans. after i run
the code, same are not displayed on the screen. 'this' gets all the
values which i need to display, but not displayed on screen.
I don't understand that question is it your capitalized method Initialize that your are talking about ? you should post the whole bean as well cuz it's never called here.
Related
I have a condition where i need to have two radio buttond with related data in the below the buttons.
i did something like below but the selected radio button value is not getting in the backed been. Please correct where i am going wrong
<table>
<tr>
<td>
<h:selectOneRadio value="#{beenObject.adressSelection}">
<f:selectItem itemValue="Employer" itemLabel="Employer" />
</h:selectOneRadio>.
</td>
<td>
<h:selectOneRadio value="#{beenObject.adressSelection}">
<f:selectItem itemValue="Consultant" itemLabel="Consultant" />
</h:selectOneRadio>.
</td>
</tr>
<tr>
<td>
<h:outputText value="#{beenObject.consultentDetailsString}">
</h:outputText>
</td>
</tr>
<tr>
<td>
<h:outputText value="#{beenObject.employerDetailsString}">
</h:outputText>
</td>
</tr>
</table>
I'm facing an issue similar as yours however I tried to replicate my situation at your code. While I was simplifying the lines I just end-up fixing your bug.
Below the code wich will work for you.
<table>
<tr>
<td>
<h:selectOneRadio value="#{beenObject.adressSelection}">
<f:selectItem itemValue="Employer" itemLabel="Employer" />
<f:selectItem itemValue="Consultant" itemLabel="Consultant" />
</h:selectOneRadio>
</td>
</tr>
<tr>
<td>
<h:outputText value="#{beenObject.consultentDetailsString}">
</h:outputText>
<h:outputText value="#{beenObject.employerDetailsString}">
</h:outputText>
</td>
</tr>
</table>
Explaining what I did:
I grouped the elements f:selectItem underneath f:selectItems like is shown in the sample at primeface showcase and it starts to work.
Hope it work as you want.
Cheers.
<a4j:form id="customerForm1" binding="#{customerForm.form}"
ajaxSubmit="false">
<h:inputHidden id="id" value="#{customerForm.customer.id}" />
<rich:panel id="purchaseOrderList"
styleClass="dataTablePanelStyle">
<a4j:outputPanel id="table">
<table border="1" width="100%">
<thead>
<tr align="center">
<th width="8%"><h:outputText id="headerq"
value="#{msg.distance}" styleClass="boldOutputTextStyle" /></th>
<th width="2%"><h:outputText id="ds8" value="" /></th>
</tr>
</thead>
<tbody>
<a4j:repeat
value="#{customerForm.customer.distanceTravelledList}"
var="purchaseOrderDetails" rowClasses="row1, row2">
<tr class="#{(rowIndex mod 2 eq 0)? 'row1' : 'row2'}">
<td align="center" width="10%">
<h:inputText id="distance" size="5" required="true"
value="#{purchaseOrderDetails.distance}"
styleClass="inputTextStyle">
</h:inputText>
</td>
<td><a4j:commandButton value="+"
action="#{customerForm.addDistanceTravelled}"
reRender="purchaseOrderList">
</a4j:commandButton></td>
</tr>
</a4j:repeat>
</tbody>
</table>
</a4j:outputPanel>
</rich:panel>
</a4j:form>
I have created a table where I have used a4j:repeat tag, so that the user can dynamically add the rows depending on his requirement..But when I remove this tag ie a4j:repeat frontend displays only one row ie both column name and input text field.. But when I add a4j:repeat` only the colum names are displayed ie Distance...Can any one tel Me what have I missed ??
Try this, I am using such a table for my process. It works fine for me it may help for you.
<table border="1" width="100%">
<thead>
<tr align="center">
<th width="8%"><h:outputText id="headerq"
value="#{msg.distance}" styleClass="boldOutputTextStyle" /></th>
<th width="2%"><h:outputText id="ds8" value="" /></th>
</tr>
</thead>
<tbody>
<a4j:repeat
value="#{customerForm.customer.distanceTravelledList}"
var="purchaseOrderDetails" rowKeyVar="rowIndex">
<tr>
<td align="center" width="10%">
<h:inputText id="distance" required="true"
value="#{purchaseOrderDetails.distance}"
styleClass="inputTextStyle">
</h:inputText>
</td>
<td><a4j:commandButton value="+"
action="#{customerForm.addDistanceTravelled}"
reRender="purchaseOrderList">
</a4j:commandButton></td>
</tr>
</a4j:repeat>
</tbody>
I have been working on this problem from last two days. I went through the apis possibly I could refer to but no luck.
I have been using ui:repeat as jsf facelet to render data with rows and columns
Code for reference
<ui:repeat var="pendingRequestItem" value="#{oqHomeController.allRequests}" > --JSF
<p:row rendered="#{oqHomeController.renderPendingRequest}> -- PRIMEFACES FOR ROW
<td><h:outputText value="#{pendingRequestItem.title}" /></td>
<td><h:outputText value="#{oqHomeController.pendingCount}" /></td>
</p:row>
</ui:repeat>
And the above code is resulting in the following which is very strange.
<tbody>
<td>Request for Quote 1</td>
<td>1</td>
<td>DTHEME1</td>
<td>4</td>
</tbody>
I hope it should be
<tbody>
<tr>
<td>Request for Quote 1</td>
<td>1</td>
</tr>
<tr>
<td>DTHEME1</td>
<td>4</td>
</tr>
</tbody>
Please help thanks.
Have you tried <p:dataTable> it seems that is what you are looking for:
<p:dataTable var="pendingRequestItem" value="#{oqHomeController.allRequests}">
<p:column>
<h:outputText value="#{pendingRequestItem.title}"/>
</p:column>
<p:column>
<h:outputText value="#{oqHomeController.pendingCount}"/>
</p:column>
</p:dataTable>
I have an inputText and an inputTextArea in JSF (shown below) that I carry out an ajax action on. However, after my ajax event, the values remain in the input boxes. Is there a simple way to refresh these text boxes after the commandButton is involked? Thanks.
<table>
<tr>
<td><div class="white"><H2>Comments</H2></div>
<h:inputText class="inputboxes" id="username"
value="#{commentBean.comment.commentname}" size="20">
</h:inputText><br/><br/>
<h:inputTextarea rows="5" cols="55" id="comment" class="inputbox" value="#{commentBean.comment.commentText}"
size="20" /></td>
</tr>
<tr>
<td></td>
<td><h:commandButton id="update"
action="#{commentBean.addComment(searchBean.companyId)}" class="myButton2" value="Add Comment" >
<f:ajax execute="#form" render=":results"/>
</h:commandButton></td>
</tr>
</table>
</h:form>
<h:form id="results">
<table>
<tr>
<td>
<h:dataTable value="#{commentBean.viewComments(searchBean.companyId)}" var="c">
<h:column>
<div class="commentsbox">#{c.commentText}</div>
</h:column>
<h:column>
<div class="boldfont">#{c.commentdate}</div>
</h:column>
<td><h:column>
<div class="commentname">#{c.commentname}</div>
</h:column>
</td>
</h:dataTable>
</td>
</tr>
</table>
In your view :
<f:ajax execute="#this" render=":results, username, comment"/>
In your backing bean, in the addComment() method :
comment.setCommentname(null);
comment.setCommentText(null);
or simply (I guess only)
comment = null;
Hello I have a problem with the following code. The Validator works correctly and everything is fine, my only problem is that the error messages for the validation are not displayed. Am I missing something or the problem is with the popup?
<rich:popupPanel id="popup" modal="true" height="280" width="200" resizeable="true" onmaskclick="#{rich:component('popup')}.hide()">
<f:facet name="header">
<h:outputText value="Simple popup panel" />
</f:facet>
<f:facet name="controls">
<h:outputLink value="#" onclick="#{rich:component('popup')}.hide(); return false;"> X </h:outputLink>
</f:facet>
<h:form id="newmssform">
<table class="position">
<tr>
<td>
<h:outputText class="output_text" value="New MSS Name:"/>
</td>
</tr>
<tr>
<td>
<h:inputText id="mssusernamefield" value="#{NetworkBean.newMss}">
<f:validator validatorId="NewMssValidator"/>
<f:attribute name="mssaddressfield" value="#{mssaddressfield}"/>
</h:inputText>
<h:message for="mssusernamefield" errorClass="errors"/>
</td>
</tr>
<tr>
<td>
<h:message for="mssusernamefield" errorClass="errors"/>
</td>
</tr>
<tr>
<td>
<h:outputText class="output_text" value="IP Address:"/>
</td>
</tr>
<tr>
<td>
<h:inputText id="mssaddressfield" value="#{NetworkBean.address}" binding="#{mssaddressfield}"/>
<h:message for="mssaddressfield" errorClass="errors"/>
</td>
</tr>
<tr>
<td>
<h:outputText class="output_text" value="User:"/>
</td>
</tr>
<tr>
<td>
<h:inputText id="mssuserfield" value="#{NetworkBean.mssUser}" />
</td>
</tr>
<tr>
<td>
<h:outputText class="output_text" value="Password:"/>
</td>
</tr>
<tr>
<td>
<h:inputSecret id="msspwdfield" value="#{NetworkBean.mssUserPass}" />
</td>
</tr>
<tr>
<td>
<a4j:commandButton style="border-radius: 5px; color: #FF6E00; font-weight: bold; font-size: 12px; margin-top: 5px;" value="Add New MSS"render="table,mss_table,oldIP" action="#{NetworkBean.addNewMss()}" />
</td>
</tr>
</table>
Here is the validator:
public void validate(FacesContext fc, UIComponent uic, Object o) throws ValidatorException {
String mssName = o.toString();
UIInput addressComponent = (UIInput)uic.getAttributes().get("mssaddressfield");
String address = addressComponent.getSubmittedValue().toString();
UIInput userNameComponent = (UIInput) uic.getAttributes().get("mssaddressfield");
String userName = userNameComponent.getSubmittedValue().toString();
UIInput passwordComponent = (UIInput) uic.getAttributes().get("mssaddressfield");
String password = passwordComponent.getSubmittedValue().toString();
if(mssName.isEmpty() || address.isEmpty() || userName.isEmpty() || password.isEmpty()){
addressComponent.setValid(false);
userNameComponent.setValid(false);
passwordComponent.setValid(false);
throw new ValidatorException(
new FacesMessage("Error!"));
}
}
As my prediction your message not rerender ontime
for h:message change code like below example
<a4j:outputPanel ajaxRendered="true">
<h:message for="mssusernamefield" errorClass="errors"/>
<a4j:outputPanel>
this may help you
FacesMessage consists of two Strings: summary and detail. When you call new FacesMessage("Error!") you're setting up the summary.
h:message's default behaviour is to show the detail, but not the summary. You can either tell it to show the summary: showSummary="true" or provide the detail in the FacesMessage: new FacesMessage("Error!", "Validation produced an error.")