Display popup when there are unsved inputs on dropdown change in JSF - jsf

How to display of popup when any of the two dropdowns selection changed and input values are modified using JSF. I am using valuechangelistener.
I have added a flag in my Mbean, if any of the input changes, this flag will be true. on change of the value of the dropdown, if this flag is true I need to show popup, but this is not coming

If you're using the<f:ajax/> tag inside of your dropdowns the following code snippet (especially the "onevent" attribute) might be useful:
<f:ajax render="itemsDataTable"
onevent="function(data) { if (data.status === 'success') {
alert('it works') ;} }"/>

Related

NullPointerException when executing same action multiple times

In my xhtml page, I have a search button and a p:datatable to display the search results. I added a c:if condition to hide and display the datatable.
<c:if test="#{!search_bean.isResultList}">
In my managedBean, I created the flag isResultEmpty and set it to true in my doInit(). In the action of my search button (actSearchForData), I've set it to true if my List is not empty.
private String actSearchForData() throws Exception {
if(resultList.size > 0) {
isResultEmpty = false;
}
}
Now this works without any errors the first time I execute actSearchForData and my resultList is displayed. But when I try to run actSearchForData the second time, I encounter nullpointer exception. I've tried debugging by returning isResultEmpty = true after getting the resultList but this only causes my flag to always return isResultEmpty = true.
How can I execute my search function multiple times and display the results in the datatable without getting any nullpointer exceptions?
UPDATE: I've tried using render again this time for the flag like rendered="!#{search_bean.isResultEmpty}". I no longer get nullpointerexception and my result list count displays the correct number of results but my data table does not show.
The JSF way to control conditional rendering is to use the rendered attribute like
<p:dataTable id="..."
value="#{search_bean.resultList}"
var="..."
rendered="#{not empty search_bean.resultList}" />
This will not render the datatable if resultList is null or resultList.size() is 0.
you must be getting NullPointerException (maybe) - because your "resultList" is null and still you are executing "resultList.size" inside "if(..)" statement
try something like This...
private String actSearchForData() {
if(resultList==null || resultList.size>0) {
isResultEmpty=false;
}
}
This code executes "isResultEmpty=false" - if(resultList is null)
Hope this works for you...

How to get Trinidad tr:inputText to echo its changed value instantly?

I have the following Trinidad tr:inputText field in my xhtml file that is bound to "value1" in my managed bean class; the inputText field is of type:
org.apache.myfaces.trinidad.component.core.input.CoreInputText
<tr:inputText value="#{myBean.value1}" autoSubmit="true" immediate="true" valueChangeListener="#{myBean.textChangeListener}" styleClass="stylePageTextSmallColored">
</tr:inputText>
<tr:commandButton id="btnCommit" inlineStyle="width:20" immediate="true" text="Commit" action="#{myBean.doCommit()}" styleClass="styleButton">
</tr:commandButton>
public void textChangeListener(ValueChangeEvent e) {
log.debug(">> textChangeListener: value=["+(String)e.getNewValue()+"]");
}
public String doCommit() throws Throwable {
log.debug("In doCommit: value1="+value1);
value1 = "("+value1+")";
// I update my database with the modified value1 string here; the database has the correct
// updated value1 string (with the parentheses).
// How do I get the modified value1 (above) to echo back to the screen instantly
// inside the doCommit() method with its changes?
}
When I type into this field and change its value then press the "commit" button, I can see its value properly obtained from the screen in the doCommit() method and the textChangeListener() method indicates that it has been called. I would like to make some changes to the "value1" variable and echo its value back instantly to the screen without doing another screen submit; can this be done as part of the doCommit() method or through some other mechanism/tag in the xhtml file?
Please note that this is using Trinidad and the input text class is listed above.
Update...
Thank you for the reference Jasper; I want the SAME inputText field to update itself after the setter method is called and the input text is changed (by the setter method). Thanks to the reference page that you pointed to; I tried the following and it works by using the partialTriggers attribute:
<tr:inputText id="myValue" value="#{myBean.value1}" autoSubmit="true" immediate="true" partialTriggers="myValue" valueChangeListener="#{myBean.textChangeListener}" styleClass="stylePageTextSmallColored"> </tr:inputText>
You can do so using Trinidad's Partial Page Rendering.
In short: you need to add an id attribute to your input, and have and tr:outputText component with a partialTriggers attribute where you refer to the input component.
Minimal implementation in your case would be:
<tr:inputText id="value1Input"
value="#{myBean.value1}"
autoSubmit="true"
immediate="true"/>
<tr:outputText value="value1: #{myBean.value1}"
partialTriggers="value1Input"/>

How do I compute the Selected property of a BasicLeafNode for a Dynamic Content Control - Updated 03/26/2014

I have created an XPage with the following: Started by creating a custom layout control using the Application Layout. I aded the layout control to the xpage and then dropped in a Dynamic Content Control. I configured the control as follows:
<xe:dynamicContent id="dynamicContent1" defaultFacet="GovernanceReviews"
useHash="true">
<xp:this.facets>
<xc:ccViewDocumentTemplates xp:key="DocumentTemplates"></xc:ccViewDocumentTemplates>
<xc:ccViewGovProcurementReviews xp:key="GovProcurementReviews"></xc:ccViewGovProcurementReviews>
<xc:ccViewGovRevReporting xp:key="GovRevReporting"></xc:ccViewGovRevReporting>
<xc:ccViewGovRevWOCompleted xp:key="GovRevWOCompleted"></xc:ccViewGovRevWOCompleted>
<xc:ccViewGovernanceReviews xp:key="GovernanceReviews"></xc:ccViewGovernanceReviews>
<xc:ccViewProfilesByType xp:key="ProfilesByType"></xc:ccViewProfilesByType>
<xc:ccViewProfilesWithTargetCompl xp:key="ProfilesWithTargetCompl"></xc:ccViewProfilesWithTargetCompl>
<xc:ccViewLastUpdated xp:key="LastUpdated"></xc:ccViewLastUpdated>
<xc:ccViewUserGuide xp:key="UserGuide"></xc:ccViewUserGuide>
<xc:ccViewTracking xp:key="Tracking"></xc:ccViewTracking>
</xp:this.facets>
</xe:dynamicContent>
Then I dropped in a navigator control in the left column and created BasicLeafNodes to correspond to the dynamic content control I used the href property and used the #content="" to display the correct content.
This works just fine, but I am having problems figuring out how to make the selections in the navigator highlight when they are selected. I know I need to compute the Selectd property,but I can't figure out how to get the xp:key value so I can compare it to the SubmitValue. I know this is probably something simple, but I can't figure it out.
Can someone please enlighten me.
Thanks,
MJ
ADDED 03/26/2014 - I have a feeling that it has something to do with Using the href property of the Dynamic Content Control to perform the content switching. I know that makes the BasicLeafNodes Links. So, not sure how the Navigator records which link is being executed and how to capture that.
MJ
Add a value is the submitValue property
And in the onItemClick Event
Assign the submitted value to a viewScope variable
viewScope.Selected=context.getSubmittedValue()
And finally check if the viewScope variable equals your item submit value in the selected property. This needs to be calculated
if(viewScope.Selected="byCategory"){
return true
}else{
return false
}
The following is working for me:
if(viewScope.Selected == "byCategory"){
return true
} else{
return false
}
An equality test must be made with two equal symbols (or three). One equal symbol evidently always returns true.
I did it by jQuery. Just put the following code to the custom control, which contains navigator.
$( function() {
if (window.location.hash.length > 0) {
select()
}
});
$(window).on('hashchange', function() {
select();
});
function select() {
$(".lotusColLeft .lotusMenu .lotusBottomCorner li").removeClass(
"lotusSelected")
$(".lotusColLeft .lotusMenu .lotusBottomCorner li a")
.filter(
function() {
return window.location.hash.indexOf($(this).attr(
'href')) > -1
}).parent().addClass("lotusSelected")
}

Setting value of a Radio Button Group Client Side

I need to set the value of a Radio Button Group that has two possible values. I'm able to accomplish this with SSJS, but having issues setting it via CSJS. Any help is appreciated.
I use something like this:
function setRadioValue(value)
{
var elements = document.getElementsByName ("#{id:radioGroup1}");
for(i=0;i<elements.length;i++) {
if (elements[i].value == value) {
elements[i].checked = true;
}
}
}
Then you can just call setRadioValue("This is teh value of the Radio Button I want to set")
Thanks
You need to get the the server-side generated name of the radio button group using the #{id:} method. Example:
var radioButtonGroup = XSP.getElementById("#{id:radioButtonGroupName}");
You can then use client-side Javascript to manipulate the radioButtonGroup element. I believe you need to loop over the radio buttons in the elements until you find the radio button with the desired value. You can then set its checked value to true.

How to create commandlink programmatically

We have a system built on seam/richfaces.
There's this webpage where the tables are rendered from dynamic context (from multiple different datasources, and each of them uses a different layout to represent essentially the same real world concept). As a result, this table is binded to a bean, and it's columns/layout are generated from this bean.
Now I need to add a command link on a specific column, equivalent to
<a4j:commandLink value="#{actBean.Ids}" action="#{actBean.genDetails}">
<f:setPropertyActionListener target="#{actBean.Ref}" value="#{cont}"/>
</a4j:commandLink>
in a JSF page.
The table is binded to a managed bean with
HtmlDataTable dataTable = new HtmlDataTable();
HtmlColumn column = new Column();
//some code to setup column name, value etcs
dataTable.getChildren().add(column);
//What do I do here to bind a commandlink with a property action
//listener to column?
My question is, how do I do this programmatically?
Thanks!
HtmlAjaxCommandLink commandLink = new HtmlAjaxCommandLink();
commandLink.addActionListener(new SetPropertyActionListener(target, value));
column.getChildren().add(commandLink);
where target and value are ValueExpression's. These can be created with:
ExpressionFactory.getInstance().createValueExpression(ctx, expression, expectedType)
And the required ELContext can be obained via FacesContext.getCurrentContext().getELContext()

Resources