I want to add source from property file - java

I have started using struts .I have hanged in a place ,Code is bellow
<st:submit src="getText('image.user.login')" type="image" height="21" width="44" </st:submit>
when i run this code , getText('image.user.login') message does return any value , But when i replace src="getText('image.user.login')" with value="getText('image.user.login')" than it returns value of "image.user.login" from property file.
What is reason for it , and how can i solve this issue ?
Thanks in advance

like this example illustrates in this reference submit reference struts
Render an image submit:
<s:submit type="image" value="%{'Submit'}" label="Submit the form" src="submit.gif"/>
src : Supply an image src for image type submit button. Will have no effect for types input and button.
AND
value : String Preset the value of input element.
this should answer your question if you use src you should assign a path and if you use value you can use a preset value

try this:
<st:submit key="image.user.login"/>

Related

How to submit another get attribute and keep previous one?

I'm building my first web app in Java. I came across this problem. When I have a get attribute like ?page=2 correctly submitted it goes missing after calling another get request. How can I keep the first one and append another one? Here are pics that help clear out my question
Before
After
Desired
Here are code snippets of my forms in .jsp page. This is used to sort the table with passing a column name:
<form action="GetUsersServlet" method="get">name
<input type="hidden" name="column" value="name">
<button class="sort" type="submit"></button>
</form>
How can I append the value to existing ?page=x attribute?
Use URLSearchParams method set on event click and set window.location.search to parsed params.
document.querySelector("button").onclick = () => {
const urlParams = new URLSearchParams(window.location.search);
urlParams.set("page", 2)
window.location.search = urlParams.toString()
}

URL changing link

On my HTML-page I have a link for saving recipe, example
addrecipe?id=607691&name=Soft-Bread-Salami-Rolls
It looks like the correct URL when I hold the mouse over the link,
but the browser(?) converts it to something like this
addrecipe?id=607691%26name%3DSoft-Bread-Salami-Rolls
I managed to put atleast id= in the html but I get error when trying to add name= also.
<a th:href="#{'/addrecipe'(id=${recipesinfo.link})}" th:text=Save></a>
Looking at the docs and assuming recipesinfo.link contains your 607691 ID (and nothing else), I think you should be using
<a th:href="#{/addrecipe(id=${recipesinfo.link},name='Soft-Bread-Salami-Rolls')}">Save</a>
If the name value comes from a variable (eg recipesinfo.name), then you would use name=${recipesinfo.name} instead of the string literal.

How to show an image conditionally in Thymeleaf?

I have a controller that returns a ReponseEntity<byte[]> image and I can show it with the following tag:
<img th:src="#{'./my-files/main-logo'}"
I can also show an image from the /img/ folder with this tag:
<img th:src="#{/img/default-logo.png}"
I want to show the image from the database when it is present, and the image from the folder as a default if the ResponseEntity is null.
I tried all kind of ternary conditions but none of them worked.
Any suggestions?
Try using the attribute th:if="${...}" in your <img /> tag.
You can try to call the method which returns the image programatically (e.g. nameOfTheImageController.getImage(...)) and add a boolean to your model that represents whether the image is null or not.
Then, you can just add that boolean variable in the <img>'s th:if.
UPDATE
As mentioned in a comment in
HTML, Thymeleaf - displaying an image conditionally, you should wrap your <img> tag inside a <div> and put the th:if attribute in the <div> tag instead.
In my opinion, instead of changing the src of the image, you should change your /my-files/main-logo controller to return img/default-logo.png as a the ResponseEntity<byte[]> if there is no main-logo. That way you can just leave your image tag as is:
<img th:src="#{'./my-files/main-logo'}" />
If you don't want to do that, then yes, you'll have to add something to your controller that tells you whether or not you have a main logo. Something like this for example:
<img th:if="${has_logo}" th:src="#{'./my-files/main-logo'}" />
<img th:unless="${has_logo}" th:src="#{/img/default-logo.png}" />
Please use the following syntax. in your controller add a model attribute hasImageInDatabase when response is null. then from thymeleaf use the below syntax.
<img th:src="${(hasImageInDatabase ?: '/my-files/main-logo': '/img/default-logo.png'}"/>
This will work for you:
<img th:src="./my-files/main-logo" onerror="this.onerror=null;this.src='/img/default-logo.png';">
It means if the first link to the photo didn't work ("./my-files/main-logo" ) or was null, it will show the second photo('/img/default-logo.png').

Extract DOM property value using Selenium

In Firebug and other DevTools you can get the DOM properties and values corresponding to an HTML element.
How can such values be extracted using selenium-java code?
I had tried getAttribute(), but it seems to be working only for HTML attributes and not for DOM properties like "value" or "spellcheck" etc.
The reason I went for this approach is that the value associated with the <input> text field (snippet below) is run-time generated and data is bound to it using Knockout. And hence it's not possible to capture them with standard approaches like getText(), getAttribute("value"), getAttribute("text"), getAttribute("innerHTML"), getAttribute("innertext"), etc.
HTML snippet for the HTML element:
<input class="form-control" type="text" style="cursor: text" readonly="readonly" data-bind="textInput: url">
I know this is an old question but it might give someone else a hand out
Use this in the console
$$("input.form-control").value
if it returns the required you will have to execute the Javascript using WebDriver i.e.
driver.ExecuteScript("var data = arguments[0].value; return data;", (Element as RemoteWebElement)
According to the Selenium documentation, there is only the getAttribute() function, which is described as follows:
Get the value of a the given attribute of the element. Will return the current value, even if this has been modified after the page has been loaded. More exactly, this method will return the value of the given attribute, unless that attribute is not present, in which case the value of the property with the same name is returned (for example for the "value" property of a textarea element). If neither value is set, null is returned. ...
According to this, getAttribute("value") should return the DOM property value in case there is no HTML attribute named value.
If that's not the case, it may be a timing issue. I.e. the value is read by Selenium before it gets set.
In Selenium 4 use getDomAttribute() and getDomProperty().

Select/click on checkbox by labelin Selenium

I have the following html code and would like to select checkbox by label:
<input type="checkbox" onclick="searchResult(this,'8')" id="catalog-8"/>
<label for="catalog-8">
my-assortment </label>
in the above example, by the value "my-assortment"
I tried this: //label[containts('my-assortment')] but it does not work.
More exactly, I want to write something like this:
//input[#type='checkbox'] which has "id" of the value of "for"
in label[contains(., 'my-assortment')]
Does anybody have any idea?
//label[containts('my-assortment')]
First of all, this is not containts - it should be contains (watch the extra t). And, you are not using contains() correctly. It should be:
//label[contains(., 'my-assortment')]
Also, if you want to click the input element by label, preceding-sibling would help here:
//label[contains(., 'my-assortment')]/preceding-sibling::input[#type='checkbox']

Categories