how to use JSF Converter when the property is not uniquely identifiable - jsf

In my JSF page, I have a <rich:autocomplete/> which must be filled by selecting an object from the list. The id of the object does not have useful meaning, so I have to write a Converter to change it to readable string.
Unfortunately the string representation of the object could not uniquely identify different objects and so the conversion is not reversible. Now I want to know how I could solve this problem? Is it possible to store the id of the selected object into a <h:inputHidden> and pass it to the view scoped backing bean?

You're using the input component and the converter the wrong way. You are apparently using the object's string representation (the item label) as input value, while you should be using the object's unique identifier (the item value) as input value. The converter is merely to convert between the custom object and the unique identifier, not between the custom object and the string representation.

I have searched this and until the moment there are no direct solution provided by the rich:component as it does not has itemValue like rich:select
Also there are 2 workaround solution.
to use JavaScript to add the id value of the selected item to a
hidden field and then use this hidden field to identify the
selected item
I used the fetchValue attribute to concat item_id - item_name
then I created a converter which substring the item_id to identify
the selected item.

Related

Question about the [PXDimension] attribute

If I set up my own segmented key ID to be used with a custom DAC's identity field, Do I need anything else other than the [PXDimension] attribute on that DAC field to implement the enforcement of that segment setup?
You would have to define your custom field with the [PXDimensionSelector] attribute.
When this attribute is used, the first parameter should be the dimension name (defined in the Segmented Keys page - CS202000), followed by the ID value (this is the value persisted in the DB), and then the CD value (this is the user-friendly value).
For instance, the Item Class Dimension selector can be defined like this:
[PXDimensionSelector(INItemClass.Dimension,
typeof(Search<INItemClass.itemClassID, Where<INItemClass.stkItem, Equal<False>>>), typeof(INItemClass.itemClassCD), DescriptionField = typeof(INItemClass.descr))]
When the value is then added to the UI, the framework will recognize the Dimension-selector attribute and it will create it as a PXSegmentMask field instead of a regular PXSelector

Dynamically Update a Component based on Another Component's Value Expression in JSF View

I have looked into the possibilities of facelet tag files, custom components, custom renderers, but couldn't figure this out. Highly appreciate if someone can direct me in a possible solution. Here's what I need to do
I have a lot of label, input, message sections in my views. So what what basically want to is to avoid adding 3 tags and achieve it by using 1 custom tag such as
<my:input value="#{customerBean.customer.name}"/>
I already know the label of the field from the customer entity field annotation like
#Field(label = "Customer Name")
private String name;
My question is, how can I get the entity value from the value expression customerBean.customer.name. So that I can find out the entity field annotation label via reflection.
I cannot always depend on the literal name "customer" as it could also be "customerBean.record.name" or something similar
I also want to avoid passing the entity name as an attribute.

How to pass a static field value with user entered value to managed bean with input field in jsf

I have a JSF page code snippet like below:
<h:inputText value="#{locConfigBB.fetchFldVal('FACEBOOK_PAGE_URL')}"/>
<h:inputText value="#{locConfigBB.fetchFldVal('TWITTER_ID')}"/>
My pojo 'FieldDetail' class has two attributes named 'fieldInternalName' & 'fieldInternalValue'.
The above code gives me value stored in the database associated with the 'fieldInternalName', which I am passing as parameter (e.g. 'TWITTER_ID').
But now my requirement is, if my database doesn't contain records with the given 'fieldInternalName' (i.e. 'TWITTER_ID'), I need to enter a value in the input text so that I will have a list of 'FieldDetail' (which will create records as per my user input)
It means if I would enter a value in the inputText field with label 'Facebook Id' n submit the form then my list in the baking bean will contain only one object
I had tried to search and explore but couldn't get right way to solve this problem.
How can I pass both the static value n user enterd value together to managed bean that create a list of objects ?
I would be very much greateful if anybody can help. Thanks in advance.
Let me know if further information required.

Is it possible to create a write only fields bindings in Java Server Faces?

I am creating a form in JSF to save a new entity bean. I binding the properties of the new entity to input elements use the value property e.g. , where backing bean is JSF managed mean and newEntity is filed of the backing bean whcih contains a new instance of my entity. For properties which are value types (like numbers), the input fields will be populated with default values (e.g. 0). I want all the fields to be blank initially and saved back the new entity instance when the page is submitted. I suppose I could make all the properties null able by using types such as Integer but the values aren't null able in the database and it doesn't seem right that the requirements of my user interface should dictate the form of by business layer. I am looking at this the wrong way?
I assume that if the fields aren't nullable, then they are required. If you put required="true" on the field, then validation should fail before the value can be assigned. This means it won't try to assign null values to your attribute. You may have to write a custom validator to do this for some types of fields.
Alternatively, you can write a converter. This converter would have to convert empty values to some predetermined constant such as -1 that you know is invalid. And vice versa, it would have to convert -1 to empty value for display. Then you have to deal with all the invalid values before sending it to the business layer.
I've used both of these methods, but I much prefer the first. If the fields are not required, they should be nullable in the business layer.

Removing ';#' from SharePoint ListItem data

In SharePoint many fields id-value pairs that are formatting like the following id;#value. This is further complicated with fields like multi-lookup where when extracting the value of that field can yield results like id_1;#value_1;#id_2;#value_2;#id_3;#value_3
I am wondering if there is any known built in function that will simplify this process and at the very least remove the IDs from the value.
Field value objects are stored as strings in the Sharepoint database. For simple values (e.g. "Hello world") this is simple enough. But for complex field values - such as an ID/value pair, how to store the entire value as a single string is obviously more complex as well. Each field value class in Sharepoint is responsible for its own storage implementation. ToString() is responsible for writing a string representation of the value; while the field value's constructor takes a string and is responsible for parsing that and setting all the properties on itself appropriately.
For example, the SPFieldUrlValue (which represents an description) has Url and Description properties. Creating a new SPFieldUrlValue(string fieldValue) object will parse the value and set the properties accordingly.
In order to get a true/correct (and often strongly-typed!) representation of the field value, you must know what type the field is, and what that field's value class is.
The SPField class has many derived classed
For example assuming a Lookup field type (that uses the ID;#value) you can check SPField.Type == SPFieldType.Lookup and then cast SPField to SPFieldLookup and use its overriden methods to get the records value.
See Custom Field Value Classes for more details
Also - If I remember correctly (I can't check this right now so DYOR) you can call .ValueAsText and .ValueAsHtml on the base SPField object and it will remove ID;# from the values.

Resources