Thymeleaf multiple result in condition

I want to check some condition basing on statement ‘myStatus’ and if it is true – change background color to red and disable element (user could not click it), if it is false – change color to green. I know how to change color (and it works fine):

th:style="${myObject.myStatus} == true ? 'background-color:red' : 'background-color:green'"

but how is it possile to disable element in this line? I tried something like:

    th:style="${myObject.myStatus} == true ? 'background-color:red'  'disabled:false' : 'background-color:green'"

    th:style="${myObject.myStatus} == true ? 'background-color:red'  'disabled' : 'background-color:green'"

    th:style="${myObject.myStatus} == true ? 'background-color:red' & disable : 'background-color:green'"

but it doesnt work… how is it possible to solve this problem?

How to secure the JS application before ‘Cannot read property“…”’?

I get a list of users using the controller.

@ApiOperation(value = "Find users")
@GetMapping(produces = MediaTypes.HAL_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public
PagedResources<UserSearchResultResource> findUsers(
        @ApiParam(value = "Search for a phrase") @RequestParam(required = false) final String q,
        @PageableDefault(sort = {"id"}, direction = Sort.Direction.ASC) final Pageable page,
        final PagedResourcesAssembler<UserSearchResult> assembler
) {
    log.info("Called with q {}, page {}", q, page);

    // Build the self link which will be used for the next, previous, etc links
    final Link self = ControllerLinkBuilder
            .linkTo(
                    ControllerLinkBuilder
                            .methodOn(UserRestController.class)
                            .findUsers(q, page, assembler)
            ).withSelfRel();

    return assembler.toResource(this.userSearchService.findUsers(
            q, page
    ), this.userSearchResultResourceAssembler, self);
}

Users are returned using the object PagedResources. For example, this object looks like this https://zapodaj.net/919677fc0ff76.png.html. Download elements using Angular

$http({
        url: '/api/v1.0/users',
        method: "GET",
        params: {
            q: angular.element('#search-value').val(),
            size: parseInt($scope.size),
            page: (parseInt($scope.page)-1)
        }
    })
        .then(function (response) {
            $scope.users = response.data._embedded.userSearchResults;
        });

Everything is fine until the controller returns an object without elements, because there are no such users https://zapodaj.net/d3bcd74bb5c00.png.html
JS throws the error

TypeError: Cannot read property 'userSearchResults' of undefined
at users.js:33
at angular.js:16832
at m.$digest (angular.js:17971)
at m.$apply (angular.js:18269)
at l (angular.js:12387)
at XMLHttpRequest.A.onload (angular.js:12541) "Possibly unhandled rejection: {}"

Because the object does not have a list of users at this time

._embedded.userSearchResults;

How can I create support for this error so that in the case when there are no users with the given name, it would set an empty list in Angular.

Updating Lamda Expression 1.6 to 8 or Higher

I just want to ask if someone can translate this to a normal method or convert this to lamda expression 8 or higher

 public void waitUntilDocIsReady() 
 {
    new WebDriverWait(driver, 30).until((ExpectedCondition<Boolean>) wd ->
    ((JavascriptExecutor) wd).executeScript("return document.readyState").equals("complete"));
 }

Thank you everyone! I’m really sorry for asking this question. I hope someone can answer this.

CSS and JS not loading on JSP servlet mapping

When I don’t have a servlet attached to a / in servlet mapping

<servlet-mapping>
    <servlet-name>ControllerServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

All my css and javascript frameworks are loading. However, when I added this part of code in web.xml, none of the css and javascript are loading. How do I ensure that the servlet knows that it is a css/js file instead of a method?

web.xml

<context-param>
        <param-name>jdbcURL</param-name>
        <param-value>jdbc:mysql://localhost:3306/bookstore</param-value>
    </context-param>

    <context-param>
        <param-name>jdbcUsername</param-name>
        <param-value>root</param-value>
    </context-param>

    <context-param>
        <param-name>jdbcPassword</param-name>
        <param-value>12345</param-value>
    </context-param>

    <servlet>
        <servlet-name>ControllerServlet</servlet-name>
        <servlet-class>net.codejava.javaee.bookstore.ControllerServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>ControllerServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <error-page>
        <exception-type>java.lang.Exception</exception-type>
        <location>/Error.jsp</location>
    </error-page>
</web-app>

ControllerServlet

public class ControllerServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private BookDAO bookDAO;

    public void init() {
        String jdbcURL = getServletContext().getInitParameter("jdbcURL");
        String jdbcUsername = getServletContext().getInitParameter("jdbcUsername");
        String jdbcPassword = getServletContext().getInitParameter("jdbcPassword");

        bookDAO = new BookDAO(jdbcURL, jdbcUsername, jdbcPassword);

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String action = request.getServletPath();

        try {
            switch (action) {
            case "/new":
                //showNewForm(request, response);
                break;
            case "/insert":
                //insertBook(request, response);
                break;
            case "/delete":
                //deleteBook(request, response);
                break;
            case "/edit":
                //showEditForm(request, response);
                break;
            case "/update":
                //updateBook(request, response);
                break;
            default:
                listBook(request, response);
                break;
            }
        } catch (SQLException ex) {
            throw new ServletException(ex);
        }
    }

    private void listBook(HttpServletRequest request, HttpServletResponse response)
            throws SQLException, IOException, ServletException {
        List<Book> listBook = bookDAO.listAllBooks();
        request.setAttribute("listBook", listBook);
        RequestDispatcher dispatcher = request.getRequestDispatcher("BookList.jsp");
        dispatcher.forward(request, response);
    }
}

jsp page

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>

        <!-- JS -->     
        <script src='static/js/bootstrap.min.js'></script>
        <script src='static/js/vue.min.js'></script>

        <!-- CSS -->
        <link rel="stylesheet" type="text/css" href="static/css/bootstrap.min.css">
        <link rel="stylesheet" type="text/css" href="static/css/common.css">
     </head>
<body>
    <center>
        <h1>Books Management</h1>
        <h2>
            <a href="new">Add New Book</a>
            &nbsp;&nbsp;&nbsp;
            <a href="list">List All Books</a>

        </h2>
    </center>
    <div align="center">
        <table border="1" cellpadding="5">
            <caption><h2>List of Books</h2></caption>
            <tr>
                <th>ID</th>
                <th>Title</th>
                <th>Author</th>
                <th>Price</th>
                <th>Actions</th>
            </tr>
            <c:forEach var="book" items="${listBook}">
                <tr>
                    <td><c:out value="${book.id}" /></td>
                    <td><c:out value="${book.title}" /></td>
                    <td><c:out value="${book.author}" /></td>
                    <td><c:out value="${book.price}" /></td>
                    <td>
                        <a href="edit?id=<c:out value='${book.id}' />">Edit</a>
                        &nbsp;&nbsp;&nbsp;&nbsp;
                        <a href="delete?id=<c:out value='${book.id}' />">Delete</a>                     
                    </td>
                </tr>
            </c:forEach>
        </table>
    </div>  
</body>
</html>

Postman link checker crawl on one page

I am using postman link checker (http://blog.getpostman.com/2017/06/23/check-for-broken-links-on-your-website-using-a-postman-collection/). Is there any way to check all links that are on xx page and not crawl those links?

// get environment variables
var start_url = postman.getEnvironmentVariable('start_url');
var root_url = postman.getEnvironmentVariable('root_url');
var links = JSON.parse(postman.getEnvironmentVariable('links'));
var url = postman.getEnvironmentVariable('url');
var index = parseInt(postman.getEnvironmentVariable('index'));

// increment index counter to access links in array to check
index = index + 1;

// test if link works
if (responseCode.code > 400) {
    //console.log("This link is broken: ", url);
    tests[("This link is broken: ", url)] = false;
} else {
    tests["Link works"] = true;
}

// if the current url includes the start_url, then this is an internal link and we should crawl it for more links
if (url.includes(start_url)) {

    // load the response body as HTML using cheerio, get the <a> tags
    var $ = cheerio.load(responseBody);

    $('a').each(function (index) {

        var link = $(this).attr('href');

        // add links to the links array if not already in there
        // if you have additional links you would like to exclude, for example, ads, you can add this criteria as well
        if (!links.includes(link)) {
            links.push(link);
        }
    });
}

// if we've gone through all the links, return early
if (links.length - 1 === index) {
    console.log('no more links to check');
    return;
}

// if link is a relative one, prepend with root_url
url = links[index]
if (! /^https?:///.test(url)) {
    url = root_url + url;
}

// update environment variable values
postman.setEnvironmentVariable("links", JSON.stringify(links));
postman.setEnvironmentVariable("url", url);
postman.setEnvironmentVariable("index", index);

// continue calling the same request until all links are checked
postman.setNextRequest('Check URL');