Is there a way to add expression in RequestContext.getCurrentInstance().update("anyExpression")? - jsf

can we add ID ends with selection expression like RequestContext.getCurrentInstance().update("#([id$=myId])");
which will update all the DOM components ending with id 'myId'. i don't want to mention this expression in xhtml. The attached image shows the generated IDs.DOM structure with generated IDs. if I mention ID as form:myTableLocalId:4:myId
then it updates only single component. I want to update all the components ending with ID 'myId'

what you are looking for is expecting jsf to identify all the dom elements and update the elements ending with some specific name unfortunately JSF is not providing such type of facilities it's containing logic so you need to write logic to find all the elements ID of the DOM elements then pass the ID and JSF will update them.
You can call a Javascript function and then in Javascript you can find all the id which is ending with your matching id and then update them since now you are having ID you can do it easily.

Related

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.

Using a composite template

I'm trying to figure out when I need to set a sequence order# for a server template and whether I need to do the same for a composite template. Here is the problem I'm trying to address: my envelopes will have 3 or 4 documents, each document will have its own template. I will have inline templates for each document, it will be the same signer roles on each document. If I have multiple document/template pairs in an envelope, does that mean I have to use a composite template? If I am using multiple server templates for a doc, for example, is that when the sequence order is important? I just need to understand these composite templates more.
If I have multiple document/template pairs in an envelope, does that mean I have to use a composite template?
Yes.
If I am using multiple server templates for a doc, for example, is that when the sequence order is important?
Sorry I'm not an expert on this yet. There are several StackOverflow questions about Compositing Templates, check them out.
Also, what's best is to try out a test envelope. If it doesn't work the way you expect, then ask a new, specific, question about your code.
You must use composite templates. The sequence of the documents in the envelope will follow the structural sequence of your compositeTemplate elements.
Each compositeTemplate element has one or more serverTemplates and/or inlineTemplates. Each template element of those arrays has a sequence element with an integer value. These values should form a sequence within that composite, and determines the order in which a document is derived for the composite and the order of overwriting that takes place for other envelope elements.
The document contributed to the envelope by a single composite is either explicitly provided via the composite::document node, or if not present, by the first (lowest sequence value) template within the composite that can contribute a document, such as a serverTemplate document or an inlineTemplate::documents node.
Overwriting envelope elements follows the "last in gets final overwrite" approach. Thus the value specified in the last (highest) sequence template overrides all previously set values.

JSF displaying entities with IDs: how to translate IDs to descriptions?

In a JSF page I have to display the data from an entity.
This entity has some int fields which cannot be displayed directly but need to be translated into a descriptive string.
Between them some can have a limited number of values, others have lots of possible values (such as a wordlwide Country_ID) and deserve a table on the Db with the association (ID, description).
This latter case can easily be solved navigating via relationship from the original entity to the entity corresponding to the dictionary table (ID, description) but I don't want to introduce new entities just to solve translations form ID to description.
Besides another integer field has special needs: the hundred thousand number should be changed with a letter according to a rule such as 100015 -> A00015, 301023 -> C01023.
Initially I put the translation code inside the entity itself but I know the great limits and drawbacks of this solution.
Then I created a singletone (EntityTranslator) with all the methods to translate the different fields. For cases where the field values are a lot I put them inside a table which is loaded from the singletone and transformed in a TreeMap, otherwise the descriptions are in arrays inside the class.
In the ManagedBean I wrote a getter for EntityTranslator and inside the jsf I use quite long el statements like the following:
#{myManagedBean.entityTranslator.translateCountryID(myManagedBean.selectedEntity.countryID)}
I think the problem is quite general and I'm looking for a standard way to solve it but, as already stated, I don't want to create new 'stupid' entities only to associate an ID to a description, I think it is overkill.
Another possibility is the use of converters Object(Integer) <-> String but I'm more comfortable in having all the translation needs for an Entity inside the same class.
Your question boils down to the following simple line:
How can I display a field different from id of my entity in my view and how can I morph an integer field into something more meaningful.
The answer is that it depends on a situation.
If you solely want to input/output data, you don't need id at all apart from the possible view parameter like ?id=12345. In this case you can input/output anything you want in your view: the id is always there.
If you want to create a new entity most possibly you have a way of generating ids via JPA, or database, or elsehow besides the direct input from the user. In this situation you don't need to mess with ids as well.
If you want to use information on other entities like show user a dropdown box with e.g. a list of countries, you always have the option to separate label (let it be name) and value (let it be id), or even have a unique not null column containing the country name in your database table that will serve as a natural identifier. If you'd like to get data from the user using an input text field you always can create a converter that will do the job of transforming user input strings to actual entity objects.
Regarding the transformation of your integers, you've actually got several choices: the first one is to attach a converter for these fields that will roughly do 301023 -> C01023 and C01023 -> 301023 transformations, the second one is to write a custom EL function and the third one is to prepare the right model beforehand / do the transformations on-the-fly.

Orchard CMS - Query based on values from ContentPicker

EDIT: Rephrased issue
I think there is either a bug or I am doing something wrong.
I add a field to the type Blogpost. This field is of type
Contentpicker. I call it Related Page.
Then I create to regular pages (ContentType Page).
I create 4 blogposts. Two blogposts get PageOne as selected value in the RelatedPage field. The other two posts get PageTwo as selected value in the RelatedPage.
Now I create a query with filter ContentType is BlogPost. And a filter with Blog Post.Related Page equals {21} (that is the Id of PageOne).
I would expect to get results BlogPostOne and BlogPostTwo. Instead I don't get results. Actually I wanted the pageid to be retrieved from the page the widget is placed on but couldn't get it to work, so I reduced back to a predefined value instead of dynamic for the filter. But like I said no results.
So is the query wrong and how should I do it then. Or is there a bug with filters for ContentPicker fields.
P.S. I will also submit an issue in Codeplex.
UPDATE
In Tokenizer all the values that contain { } are being seen as tokens and therefore are replaced. The problem is that the Ids of content items in a contentpicker field are stored with accolades. So when having {21} as the value for the filter, 21 gets tokenized and since there is no value for this token the value becomes empty. When skipping the tokenizer it works (while debugging). But one cannot skip the tokenizer, because it is very legitimate that there is a token present.
So I believe there is a bug with either the tokenizer, or the way the ids are stored in the contentitem field for contentpicker. I think it can be solved by changing the contentpicker to store numbers separated with comma's but without the accolades.
have you tried using the alias of the page instead of content id as the identifier? e.g. "/about-us", like you do in the layer rules.

JSF 2 - Dynamically added component's ids are not retained on postback

I have a facet within a component within which i add components dynamically using
UIComponent c = new UICustomComponent();
c.setId("someIdGeneratedDynamically");
facet.getChildren().add(c);
But on postback, when i iterate over this list, i realize that the components are present but their ids are different from the ones i specified earlier. (more specifically, these ids are of the form "j_id9, j_id10" etc)
I debugged a bit of code in StateManagementStrategyImpl and realized that they are deliberately not storing the component ids while saving the view.
My question is, why doesn't JSF store the component id?
To answer your question stated at the end: in RestoreView phase, JSF rebuilds requested view from the template file(s). It is assumed components always receive the same ids as long as the templates don't change. The state is saved using clientIds as keys. If you modified the clientId programmatically it would be impossible to restore the state properly: the recreated component would have the original id and its state would be stored under another (modified) id. That's why it doesn't "store" clientId, it's that thing that's expected to remain constant and allows matching the recreated component with its state from the previous request.
I believe this behavior applies only to components created from the templates. JSF has a dedicated mechanism to handle programmatically added components and I would expect this mechanism to deal with clientIds as expected.

Resources